<template>
	<view>
		<view class="noe">
			<text>{{name}}</text>
		</view>
		<view class="list">
			<view @click="navigateTo(item)" v-for="(item,index) in list" class="on">
				<view class="left">
					<text>{{item.name}}</text>
				</view>
				<view class="right">
					<i></i>
				</view>
			</view>
		</view>
	</view>
</template>

	<script>
		import {mapMutations} from 'vuex'
		import {buildingList} from '../../api/building.js'
		import {houseslist} from '../../api/houses.js'
		export default{ 
			data(){
				return{
					 list:[],
					 pid:0,
					 name:"",
					 delta:0
					 
				}
			},
		 onLoad: function (option) { 
			 this.delta=parseInt(option.delta);
			 this.pid=option.pid;
			 console.log(123,option.name)
			 this.name=option.name;
				 this.getBuildList();
					 
		  },
			created() {
				
				
				
			},
			methods:{
		   ...mapMutations({updateHouse:'house/update'}),
				 
			 navigateTo(item){
				 
				 
				 if(item.houseno){
					 
					 console.log(100,this.delta);
					 
					 this.updateHouse({name: this.name+item.houseno,id:item.id});
					 
					 uni.navigateBack({
					 	delta:this.delta
					 })
					 
					 
					 // uni.showModal({
					 // 	title:"你选择了"+item.houseno,
						
					 // })
				 }
				 else if(item.leaf==1){
					 
					 this.name+=item.name;
					 this.getHouseList(item.id);
					 
					
				 }
				 else{
					 uni.navigateTo({
					 	url:"/pages/houses/list?pid="+item.id+"&name="+this.name+item.name+"&delta="+(this.delta+1)
					 })
				 }
				 
				
					 
			  },
			  async getHouseList(buildingid){
			  	  
			  	 const res= await houseslist({buildingid:buildingid,psize:10000});
			  	 
				this.list=res.data.list.map(item=>
				  ({
			
					  ...item,name:item.houseno
				  }));
				   //this.list=res.data.list;
				 
				 //console.log(111111111,JSON.stringify(_list))
			  	 
			  	 
			  },
			  async getBuildList(){
				  console.log({pid:this.pid})
				 const res= await buildingList({pid:this.pid});
					if(res.errCode == '10000') {
						this.list=res.data.list;
					}
				
				 
				}
			}
		}
	</script>
	
 

<style scoped lang="less">
	.noe{
		width: 750rpx;
		height: 80rpx;
		background-color: #f0f0f0;
		text{
			font-size:22rpx;
			line-height:78rpx;
			margin-left:29rpx;
		}
	}
	.list{
		width: 750rpx;
		height: 330rpx;
		.on{
			width:718rpx;
			height:98rpx;
			border-bottom:1rpx solid #f0f0f0;
			margin-left:32rpx;
			display:flex;
			align-items: center;
			justify-content: space-between;
			.left{
				text{
					font-size: 26rpx;
				}
			}
			.right{
				display: flex;
				align-items: center;
				position: relative;
				i{
					position: absolute;
					width:20rpx;
					height:20rpx;
					border-top: 1rpx solid #8c8c8c;
					border-right: 1rpx solid #8c8c8c;
					transform:rotate(45deg);
					right:30rpx;
				}
			}
		}
	}
</style>
